﻿using JobBack.Models;
using QG.JobBack.BLL.IService;
using QG.JobBack.BLL.Service;
using QG.JobBack.DAL;
using QH.JobBack.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace JobBack.Controllers
{
    public class AdminController : BaseController
    {
        AdminService adminService = new AdminService();
        Opretation opretation = new Opretation();
        private ILogsService test;
        public AdminController(ILogsService @class)
        {
            this.test = @class;
        }
        /// <summary>
        /// 管理员列表
        /// </summary>
        /// <returns></returns>
        public ActionResult AdminList()
        {
            
            return View();
        }
        public JsonResult QueryAdminList(int page, int limit,string AdminName)
        {
            if (AdminName==null)
            {
                AdminName = "";
            }
            int count = 0;
            List<Admininfo> menus = adminService.QueryPageList(page, limit, a => a.AdminName.Contains(AdminName), a => a.AdminId);

            ResponseResult<Admininfo> getJson = new ResponseResult<Admininfo>()
            {
                msg = "",
                code = 0,
                count = adminService.GetCount(a => a.AdminId != 0, out count),
                data = menus
            };
            return Json(getJson, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 新增管理员
        /// </summary>
        /// <returns></returns>
        public ActionResult AddAdmin(string AdminId)
        {
            if (AdminId != null)
            {
                Admininfo admininfo = new Admininfo();
                admininfo.AdminId = Convert.ToInt32(AdminId);
                ViewBag.list = adminService.QueryList(a => a.AdminId == admininfo.AdminId);
            }
            return View();
        }
        /// <summary>
        /// 修改密码页面
        /// </summary>
        /// <returns></returns>
        public ActionResult UpdatePassword()
        {
            int id = this.User.Identity.Id;
            return View();
        }
        /// <summary>
        /// 删除管理员信息
        /// </summary>
        /// <param name="admininfo"></param>
        /// <returns></returns>
        public JsonResult DelAdmininfo(Admininfo admininfo)
        {
            opretation.Success = adminService.Delete(admininfo.AdminId);
            return Json(opretation);
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <returns></returns>
        public JsonResult UpdateAdminStar(Admininfo admininfo)
        {
            opretation.Success = adminService.UpdateStatus(admininfo);
            return Json(opretation);
        }
        /// <summary>
        /// 新增管理员
        /// </summary>
        /// <param name="admininfo"></param>
        /// <returns></returns>
        public JsonResult AddAdmininfo(Admininfo admininfo)
        {
            opretation.Success = adminService.AddAdmininfos(admininfo);
            return Json(opretation);
        }
        /// <summary>
        /// 修改管理员信息
        /// </summary>
        /// <param name="admininfo"></param>
        /// <returns></returns>
        public JsonResult UpdateAdmininfo(Admininfo admininfo)
        {
            opretation.Success = adminService.UpdateAdmininfos(admininfo);
            return Json(opretation);
        }
    }
}